var baseUrl = "js/img.json";
		var bg = document.querySelector(".bg")
		var load = document.querySelector(".p_one")
		var game = document.querySelector(".game");
		var plane = document.querySelector(".plane")
		var planeImg =plane.querySelector("img")
		var span = game.querySelector("span")
		var start = document.querySelector(".start")
		var bgImg = bg.querySelector(".bg_img")
		var barriers = bgImg.querySelectorAll("div")
		var shouye = document.querySelector(".shouye")
		var begins = document.querySelector(".begins")
		var ul = document.querySelector(".UL")
		var sol =0
		//点击开始后进入加载画面
		
		begins.addEventListener("click",function(){
				shouye.style.display = "none"
				var baseUrl1 = "js/img.json"
				my_ajax(baseUrl1,"get",function(res){
					var loading = new createjs.LoadQueue();
					loading.loadManifest(res);
					loading.on("progress",function(event){
						var num = Math.floor(event.progress*100)
						load.innerText=  "拼命加载中。。。。" +num+"%";
						if(num==100){
							start.style.display = "none"
						}
					})
				})
			
		//进场动画
			plane.style.animationName = "plane"
		//分数	
			var fenshu=0
			span.innerText= "分数为："+ fenshu 	
			var num2  = 3.2;
			var num3  = 0;
			var num33 = 25;
			var time
			var time1;
			var time2;
			//鼠标控制	
				mouseDown()
				function mouseDown(){
					document.addEventListener("mousedown",function(e){
//								console.log(plane.offsetLeft)
//								console.log(plane.offsetLeft+plane.offsetWidth)
//								console.log(plane.offsetTop)
//								console.log(plane.offsetTop+plane.offsetHeight)	
						out()
						//飞机左边
								if(e.offsetX<plane.offsetLeft){
								//设置最小角度
									num3++;
									if(num3==3||num3>3){
										num3=3
									}
									planeImg.style.transform = "rotate("+(180+30*num3)+"deg)"
									if(num3==0){
										clearInterval(time1)
										clearInterval(time2)
										console.log(num3)
									}else if(num3>0){
											time1 = setInterval(function(){
											out()
											num2-=0.1
											plane.style.left = num2+"rem"
										},50)
									}
								}else{
						//飞机右边		
								//设置最大角度
									num3--;
									if(num3==-3||num3<-3){
										num3=-3
									}
									planeImg.style.transform = "rotate("+(180+30*num3)+"deg)"
									if(num3==0){
										clearInterval(time1)
										clearInterval(time2)
										plane.style.left = num2+"rem"
									}else if(num3<0){
										time2 = setInterval(function(){
											out()
											num2+=0.1
											plane.style.left = num2+"rem";
											console.log(plane.offsetLeft)
										},50)
									}	
								}
							
					})
				}
				
			//背景滚动	
				var num =0,
					num1=0;
				plane.addEventListener("animationend",function(){
					time =setInterval(function(){
						fenshu+=7	
						span.innerText= "分数为："+ fenshu 
						num-=4;
						num1+=1;
						if(num1 == 570){
							num=0
							num1=0
						}
						bgImg.style.transform = "translateY("+num+"px)"
					},23)
					
				//随机生成障碍物	
					setInterval(function(){
						
					},3000)
				})
				
			var planeW = plane.offsetWidth
			console.log(planeW)
			//碰撞或者出界
				function out(){
						var min = plane.offsetLeft
					//出界	
						if(min==0 || min<0   ||min ==320-planeW ||  min>320-planeW){
								clearInterval(time)
								clearInterval(time1)
								clearInterval(time2)
							end()
						}
					//碰撞
							var planeL = plane.offsetLeft
							var planeR = plane.offsetLeft +plane.offsetWidth
							var planeT = plane.offsetTop
							var planeB = plane.offsetTop +plane.offsetHeight
						//测试取div class"le" 测试 	
							var bar1L = barriers[0].offsetLeft
							var bar1R = barriers[0].offsetLeft +barriers[0].offsetWidth
							var bar1T = barriers[0].offsetTop
							var bar1B = barriers[0].offsetTop +barriers[0].offsetHeight
							
							if( planeT > bar1B || bar1T>planeB || planeL > bar1R || bar1L > planeR){
								console.log(planeL)
								console.log(planeR)
								console.log(bar1L)
								console.log(bar1R)
							}else{
								alert(1)
								clearInterval(time)
							}
						
				}
			//游戏结束
				function end(){
					var div1 = document.querySelector(".div1")
					var div2 = document.querySelector(".div2")
					var div1P = div1.querySelector("p")
					var div2P = div2.querySelector("P")
					var share1 = div2.querySelector(".share")
					var share2 = document.querySelector(".Share")
					var back = div2.querySelector(".back")
					var rankingList1 = document.querySelector(".rankingList")
					var rankingList2 = document.querySelector(".RankingList")
					var grade = rankingList2.querySelector(".grade")
					var sub = document.querySelector(".sub")
					div1.style.display = "block";
					
					sub.addEventListener("click",function(){
						if(inp.value == null || inp.value == ""){
							alert("请输入用户名！")
						}else{
							getInto()
							div1.style.display="none"
							div2.style.display="block"
							div2P.innerText = "此次得分为:"+ " "+fenshu
							//分享
							share1.addEventListener("click",function(){
								share2.style.display = "block"
								share2.addEventListener("click",function(){
									this.style.display = "none"
								})
							})
							//排行榜
							rankingList1.addEventListener("click",function(){
								
								rankingList2.style.display = "block"
								rankingList2.addEventListener("click",function(){
									this.style.display = "none"
								})
							})
						}
					})
					
				}//点击开始按钮后
				
		//排行榜		
			var inp = document.querySelector(".userName input[type=text]")
			var ranking=1
			function getInto(){
				
				var baseUrl2 = "https://easy-mock.com/mock/5b712abe3ec6e13ce517da93/Ranking/rankingList?"
				my_ajax(baseUrl2+"name="+inp.value+"&grade="+fenshu,"get",function(res){
					console.log(res)
					//将数组按
					res.data.result.sort(function(a,b){
							return a.grade - b.grade
					})
					for(var i=0;i<res.data.result.length;i++){
						var li = "<li><span>"+ranking+"</span><span>"+res.data.result[i].name+"</span><span>"+res.data.result[i].grade+"</span></li>"
						ranking++;
						console.log(ul)
						ul.innerHTML += li
					}
				})
			}
		
		})
		
	
		
		
		
		
		

		